package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;

import javax.microedition.khronos.egl.EGLDisplay;

public class Int extends AppCompatActivity implements View.OnClickListener {

    private EditText number;
    private EditText adress;
    private SharedPreferences anInt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_int);


        adress = findViewById(R.id.int_adress);
        number = findViewById(R.id.int_number);
        Button save = findViewById(R.id.int_save);

        save.setOnClickListener(this);
        anInt = getSharedPreferences("int", 0);
        String adress1 = anInt.getString("adress", null);
        String number1 = anInt.getString("number", null);
        if(adress1 != null ){
            adress.setText(adress1);
            number.setText(number1);
        }

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(adress.getWindowToken(),0);
        return super.onTouchEvent(event);
    }

    @Override
    public void onClick(View v) {
        SharedPreferences.Editor edit = anInt.edit();
        edit.putString("adress", String.valueOf(adress.getText()));
        edit.putString("number", String.valueOf(number.getText()));
        edit.commit();
        finish();
    }
}